package com.greenhouse9.prog01;

import org.apache.commons.cli.*;

import com.greenhouse9.prog01.split.Command;
import com.greenhouse9.prog01.split.OptionSpecSplit;

public class Main {

	public static void main(String[] args){

		/* check length of arguments */
	  	if (args.length < 1) {
	  		System.out.println("Usage: java Prog1 filename ");
	  		System.exit(0);
	  	}

	  	//変数の数は" + args.length + "個です。
	  	for (int i=0; i<args.length; i++){
	  		System.out.println("変数 arg[" + i + "] は  " + args[i] + " です。");
	  	}

		OptionSpecSplit optionSpec = new OptionSpecSplit ();
		//OptionSpec optionSpec = getOptionSpec ();
		Options options = optionSpec.getOpeions();

		CommandLineParser parser = new BasicParser ();
		
		Command cm = new Command();
		
		try {
			CommandLine cl = parser.parse(options, args);
			
			cm.setCommandLine(cl);
		}
		catch (ParseException e){
			HelpFormatter formatter = new HelpFormatter ();
			formatter.printHelp(optionSpec.getName(), options, true);
			System.exit(1);
		}
		
		if(cm.validate()==-1){
			cm.printError();
			System.exit(1);
		}
		else {
			cm.execute();
			System.exit(0);
		}
  	}
	
	public OptionSpecSplit getOptionSpec(){
		return null;
	}
}
